package io.itit.ecp.admin.provide.filter;

import com.alibaba.fastjson.serializer.ValueFilter;
import io.itit.grass.common.server.helper.DictHelper;
import io.itit.grass.common.utils.CommonUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * <p>
 *
 * @Author：Roy
 * @Description：计量设备管理键值转换
 * @Date：Create by 2023-11-30 18:51:39
 */
public interface IMeterDeviceFilter {

	String DEVICE_TYPE = "deviceType" ;
	String DEVICE_STATUS = "deviceStatus" ;
	String IS_FOCUS = "isFocus" ;
	String METER_TYPE = "meterType" ;
	String READ_METER_TYPE = "readMeterType" ;
	String READ_METER_TAG = "readMeterTag" ;
//	String PURPOSE = "purpose" ;
	String STATUS = "status" ;
	String DEL_FLAG = "delFlag" ;

	String METER_DEVICE_DEVICE_TYPE = "ecp-admin.meterDevice.deviceType" ;
	String METER_DEVICE_DEVICE_STATUS = "ecp-admin.meterDevice.deviceStatus" ;
	String METER_DEVICE_IS_FOCUS = "ecp-admin.meterDevice.isFocus" ;
	String METER_DEVICE_METER_TYPE = "ecp-admin.meterDevice.meterType" ;
	String METER_DEVICE_READ_METER_TYPE = "ecp-admin.meterDevice.readMeterType" ;
	String METER_DEVICE_READ_METER_TAG = "ecp-admin.meterDevice.readMeterTag" ;
//	String METER_DEVICE_PURPOSE = "ecp-admin.meterDevice.purpose" ;
	String METER_DEVICE_STATUS = "ecp-admin.meterDevice.status" ;
	String METER_DEVICE_DEL_FLAG = "ecp-admin.meterDevice.delFlag" ;

	class MeterDeviceExportFilter implements ValueFilter {

		private Map<String, String> deviceTypeMap;
		private Map<String, String> deviceStatusMap;
		private Map<String, String> isFocusMap;
		private Map<String, String> meterTypeMap;
		private Map<String, String> readMeterTypeMap;
		private Map<String, String> readMeterTagMap;
//		private Map<String, String> purposeMap;
		private Map<String, String> statusMap;
		private Map<String, String> delFlagMap;

		public MeterDeviceExportFilter() {
			deviceTypeMap = DictHelper.i().stringVlMap(METER_DEVICE_DEVICE_TYPE);
			deviceStatusMap = DictHelper.i().stringVlMap(METER_DEVICE_DEVICE_STATUS);
			isFocusMap = DictHelper.i().stringVlMap(METER_DEVICE_IS_FOCUS);
			meterTypeMap = DictHelper.i().stringVlMap(METER_DEVICE_METER_TYPE);
			readMeterTypeMap = DictHelper.i().stringVlMap(METER_DEVICE_READ_METER_TYPE);
			readMeterTagMap = DictHelper.i().stringVlMap(METER_DEVICE_READ_METER_TAG);
//			purposeMap = DictHelper.i().stringVlMap(METER_DEVICE_PURPOSE);
			statusMap = DictHelper.i().stringVlMap(METER_DEVICE_STATUS);
			delFlagMap = DictHelper.i().stringVlMap(METER_DEVICE_DEL_FLAG);
		}

		@Override
		public Object process(Object object, String name, Object value) {
			if (StringUtils.equals(name, DEVICE_TYPE)) {
				return CommonUtils.orElse(deviceTypeMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, DEVICE_STATUS)) {
				return CommonUtils.orElse(deviceStatusMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, IS_FOCUS)) {
				return CommonUtils.orElse(isFocusMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, METER_TYPE)) {
				return CommonUtils.orElse(meterTypeMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, READ_METER_TYPE)) {
				return CommonUtils.orElse(readMeterTypeMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, READ_METER_TAG)) {
				return CommonUtils.orElse(readMeterTagMap.get(CommonUtils.toString(value)), value);
			}
//			if (StringUtils.equals(name, PURPOSE)) {
//				return CommonUtils.orElse(purposeMap.get(CommonUtils.toString(value)), value);
//			}
			if (StringUtils.equals(name, STATUS)) {
				return CommonUtils.orElse(statusMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, DEL_FLAG)) {
				return CommonUtils.orElse(delFlagMap.get(CommonUtils.toString(value)), value);
			}
			return value;
		}

	}

	class MeterDeviceUploadFilter implements ValueFilter {

		private Map<String, String> deviceTypeMap;
		private Map<String, String> deviceStatusMap;
		private Map<String, String> isFocusMap;
		private Map<String, String> meterTypeMap;
		private Map<String, String> readMeterTypeMap;
		private Map<String, String> readMeterTagMap;
//		private Map<String, String> purposeMap;
		private Map<String, String> statusMap;
		private Map<String, String> delFlagMap;

		public MeterDeviceUploadFilter() {
			deviceTypeMap = DictHelper.i().stringLvMap(METER_DEVICE_DEVICE_TYPE);
			deviceStatusMap = DictHelper.i().stringLvMap(METER_DEVICE_DEVICE_STATUS);
			isFocusMap = DictHelper.i().stringLvMap(METER_DEVICE_IS_FOCUS);
			meterTypeMap = DictHelper.i().stringLvMap(METER_DEVICE_METER_TYPE);
			readMeterTypeMap = DictHelper.i().stringLvMap(METER_DEVICE_READ_METER_TYPE);
			readMeterTagMap = DictHelper.i().stringLvMap(METER_DEVICE_READ_METER_TAG);
//			purposeMap = DictHelper.i().stringLvMap(METER_DEVICE_PURPOSE);
			statusMap = DictHelper.i().stringLvMap(METER_DEVICE_STATUS);
			delFlagMap = DictHelper.i().stringLvMap(METER_DEVICE_DEL_FLAG);
		}

		@Override
		public Object process(Object object, String name, Object value) {
			if (StringUtils.equals(name, DEVICE_TYPE)) {
				return CommonUtils.orElse(deviceTypeMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, DEVICE_STATUS)) {
				return CommonUtils.orElse(deviceStatusMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, IS_FOCUS)) {
				return CommonUtils.orElse(isFocusMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, METER_TYPE)) {
				return CommonUtils.orElse(meterTypeMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, READ_METER_TYPE)) {
				return CommonUtils.orElse(readMeterTypeMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, READ_METER_TAG)) {
				return CommonUtils.orElse(readMeterTagMap.get(CommonUtils.toString(value)), value);
			}
//			if (StringUtils.equals(name, PURPOSE)) {
//				return CommonUtils.orElse(purposeMap.get(CommonUtils.toString(value)), value);
//			}
			if (StringUtils.equals(name, STATUS)) {
				return CommonUtils.orElse(statusMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, DEL_FLAG)) {
				return CommonUtils.orElse(delFlagMap.get(CommonUtils.toString(value)), value);
			}
			return value;
		}

	}

}
